package com.cupk.rotaryguard.monitor.controller;

import com.cupk.common.base.utils.result.Result;
import com.cupk.rotaryguard.monitor.service.DiagnosisService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tjy
 * @date 2023/4/13
 * @apiNote
 */
@RestController
@RequestMapping("/diagnosis")
public class DiagnosisController {
    @Resource
    private DiagnosisService diagnosisService;

    /**
     * 获取诊断结果
     *
     * @param deviceId
     * @return
     */
    @PostMapping("/get-prediction/{deviceId}")
    public Result diagnosisDevice(@PathVariable Long deviceId) {
        return diagnosisService.diagnosisDevice(deviceId);
    }

    /**
     * 获取概率分布
     *
     * @param deviceId
     * @return
     */
    @PostMapping("/get-prediction-prob/{deviceId}")
    public Result diagnosisDeviceProb(@PathVariable Long deviceId) {
        return diagnosisService.diagnosisDeviceProb(deviceId);
    }

    /**
     * 获取故障中的设备数量
     *
     * @return
     */
    @GetMapping("/fault-count")
    public Result getFaultDeviceCount() {
        return diagnosisService.getFaultDeviceCount();
    }


    /**
     * 根据设备号获取最新10条诊断记录
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/last-ten/{deviceId}")
    public Result getLastTenDiagnosisRecord(@PathVariable Long deviceId) {
        return diagnosisService.getLastTenDiagnosisRecord(deviceId);
    }

    /**
     * 获取诊断记录
     *
     * @param pageSize
     * @param pageNum
     * @param deviceId
     * @param deviceModel
     * @param diagnosisRes
     * @return
     */
    @GetMapping("/list")
    public Result getDiagnosisRecord(@RequestParam(defaultValue = "10") Integer pageSize,
                                     @RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "") Long deviceId,
                                     @RequestParam(defaultValue = "") String deviceModel,
                                     @RequestParam(defaultValue = "") String diagnosisRes) {
        return diagnosisService.getDiagnosisRecord(pageSize, pageNum, deviceId, deviceModel, diagnosisRes);
    }

    /**
     * 单个删除
     *
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public Result delDiagnosisRecord(@PathVariable Long id) {
        return diagnosisService.delDiagnosisRecord(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public Result delDiagnosisRecord(@RequestBody List<Long> ids) {
        return diagnosisService.delDiagnosisRecords(ids);
    }
}
